package com.gzlz.budejie.view;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import com.gzlz.budejie.R;
import com.gzlz.budejie.activity.MainActivity;
import com.gzlz.budejie.activity.UploadActivity;

public class FootView extends LinearLayout implements View.OnClickListener {

	private ViewGroup foot1;
	private ViewGroup foot2;
	private ViewGroup foot3;
	private ViewGroup foot4;
	private ViewGroup foot5;

	public FootView(Context context, AttributeSet attrs) {
		super(context, attrs);
	}
	
	
	@Override
	protected void onFinishInflate() {
		super.onFinishInflate();
		foot1 = (ViewGroup) findViewById(R.id.foot_1);
		foot1.setOnClickListener(this);
		foot2 = (ViewGroup) findViewById(R.id.foot_2);
		foot2.setOnClickListener(this);
		foot3 = (ViewGroup) findViewById(R.id.foot_3);
		foot3.setOnClickListener(this);
		foot4 = (ViewGroup) findViewById(R.id.foot_4);
		foot4.setOnClickListener(this);
		foot5 = (ViewGroup) findViewById(R.id.foot_5);
		foot5.setOnClickListener(this);
		foot1.getChildAt(0).setEnabled(false);
		lastView = foot1;
	}

	ViewGroup lastView;
	
	@Override
	public void onClick(View v) {
		MainActivity activity = (MainActivity) getContext();
		if (v==foot3) {
			//TODO 启动发帖选项界面
			getContext().startActivity(new Intent(getContext(), UploadActivity.class));
			return ;
		}
		if (v==foot1) {
			activity.切换(0);
		}
		if (v==foot2) {
			activity.切换(1);
		}
		if (v==foot4) {
			activity.切换(2);
		}
		if (v==foot5) {
			activity.切换(3);
		}
		
		lastView.getChildAt(0).setEnabled(true);
		ViewGroup vg = (ViewGroup) v;
		vg.getChildAt(0).setEnabled(false);
		lastView = vg;
	}
	

}
